package com.clarence.dada.modular.system.menu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.clarence.dada.modular.system.menu.entity.SysMenuResourceEntity;
import com.clarence.dada.modular.system.menu.mapper.SysMenuResourceMapper;
import com.clarence.dada.modular.system.menu.service.SysMenuResourceService;
import org.springframework.stereotype.Service;

/**
 * 系统资源信息关联
 *
 * @author GD
 * @since 2021/8/8 21:38
 */
@Service
public class SysMenuResourceServiceImpl extends ServiceImpl<SysMenuResourceMapper, SysMenuResourceEntity> implements SysMenuResourceService {
//
//    @Resource
//    private SysResourceService sysResourceService;
//
//    @Override
//    public List<ResourceTreeNode> getMenuResourceTree(Long id) {
//        LambdaQueryWrapper<SysMenuResourceEntity> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(SysMenuResourceEntity::getId, id);
//        List<SysMenuResourceEntity> list = this.list(wrapper);
//
//        List<String> resourceCodes = list.stream().map(SysMenuResourceEntity::getResourceCode).collect(Collectors.toList());
//        return sysResourceService.getResourceList(resourceCodes, true, null);
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void addMenuResourceBind(SysMenuResourceVo sysMenuResourceVo) {
//        // 先将该业务下，模块下的所有资源删除掉
//        List<String> modularTotalResource = sysMenuResourceVo.getModularTotalResource();
//        if (ObjectUtil.isNotEmpty(modularTotalResource)) {
//            LambdaUpdateWrapper<SysMenuResourceEntity> wrapper = new LambdaUpdateWrapper<>();
//            wrapper.in(SysMenuResourceEntity::getResourceCode, modularTotalResource);
//            wrapper.eq(SysMenuResourceEntity::getBusinessId, sysMenuResourceVo.getId());
//            this.remove(wrapper);
//        }
//
//        // 再将该业务下，需要绑定的资源添加上
//        List<String> selectedResource = sysMenuResourceVo.getSelectedResource();
//        if (ObjectUtil.isNotEmpty(selectedResource)) {
//            ArrayList<SysMenuResourceEntity> menuResources = new ArrayList<>();
//            for (String resourceCode : selectedResource) {
//                SysMenuResourceEntity sysMenuResource = new SysMenuResourceEntity();
//                sysMenuResource.setBusinessType(sysMenuResourceVo.getBusinessType());
//                sysMenuResource.setBusinessId(sysMenuResourceVo.getId());
//                sysMenuResource.setResourceCode(resourceCode);
//                menuResources.add(sysMenuResource);
//            }
//            this.saveBatch(menuResources, menuResources.size());
//        }
//    }
}
